import { Component, OnInit, EventEmitter, SimpleChanges, Input, Output } from '@angular/core';
import { CoreMessageService } from '../../../core/services/core-message.service';
import { RepairService } from '../repair.service';

@Component({
  selector: 'app-detailPanel',
  templateUrl: './detailPanel.component.html',
  styleUrls: ['./detailPanel.component.scss']
})
export class DetailPanelComponent implements OnInit {

  @Input() layerdata =  { type: '', layerList: [] };
  @Output() cleardata = new EventEmitter<boolean>();
  @Output() currentSelectlayer = new EventEmitter<any>();
  radioValue = null;
  layerlist = [];
  listOfSelectedValue = [];
  constructor(private coreMessageService: CoreMessageService,
              private repairService: RepairService,) { }

  ngOnInit(): void {
    document.getElementById('selectlayer').style.paddingBottom = '20px';
  }

  ngOnChanges(changes: SimpleChanges) {
    if (changes.layerdata && changes.layerdata.currentValue) {
      this.getLayersData(changes.layerdata.currentValue);
    }
  }
  getLayersData(param) {
    // 二级菜单初始化
    this.repairService.getLayerListByType(param).subscribe(res => {
      this.layerlist = res.data;
      // 先清空
      this.listOfSelectedValue = [];
      this.layerlist.forEach(element => {
        this.listOfSelectedValue.push(element.shortname);
      });
      if (this.listOfSelectedValue.length > 0) {
        // 每次会判断一下
        document.getElementById('selectlayer').style.paddingBottom = '20px';
        document.getElementById('show').style.display = 'none';
        }
    });
  }
  // 执行查询操作
  static() {
    if (this.listOfSelectedValue.length > 0) {
      const formatparam = { layer_arr: this.listOfSelectedValue};
      this.currentSelectlayer.emit(formatparam);
    } else {
      document.getElementById('selectlayer').style.paddingBottom = '0px';
      document.getElementById('show').style.display = 'block';
    }
  }
  // 清空所有选择项以及内容
  clearAll() {
    this.listOfSelectedValue = [];
    // 清空渲染
    this.cleardata.emit(true);
  }

  // 关闭提示语
  closeTip(){
    document.getElementById('selectlayer').style.paddingBottom = '20px';
    document.getElementById('show').style.display = 'none';
  }
}
